package edu.hitsz;

import edu.hitsz.application.ImageManager;
import edu.hitsz.application.Main;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.BufferedImage;
import java.awt.image.ImageObserver;
import java.awt.image.ImageProducer;

public class StartGame extends JPanel{
    private JButton easyButton;
    private JButton hardButton;
    private JPanel main;
    private JPanel music;
    private JLabel musicLabel;
    private JRadioButton openMusic;
    private JRadioButton closeMusic;
    private JButton normalButton;
    private JLabel titleImg;
    public static String selectPattern;
    public static boolean isPlay = true;

    public StartGame() {

        BufferedImage image1 = ImageManager.TITLE_IMAGE;
        ImageIcon img = new ImageIcon(image1.getScaledInstance(Main.WINDOW_WIDTH,Main.WINDOW_HEIGHT / 2,Image.SCALE_DEFAULT));
        titleImg.setIcon(img);
        BufferedImage image2 = ImageManager.BUTTON_IMAGE;
        ImageIcon img2 = new ImageIcon(image2.getScaledInstance(200,70,Image.SCALE_DEFAULT));
        easyButton.setIcon(img2);
        easyButton.setBorderPainted(false);
        normalButton.setIcon(img2);
        normalButton.setBorderPainted(false);
        hardButton.setIcon(img2);
        hardButton.setBorderPainted(false);

        easyButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                selectPattern = "edu.hitsz.application.EasyGame";
                synchronized (Main.object){
                    Main.object.notify();
                }
            }
        });
        normalButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                selectPattern = "edu.hitsz.application.NormalGame";
                synchronized (Main.object){
                    Main.object.notify();
                }
            }
        });
        hardButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                selectPattern = "edu.hitsz.application.HardGame";
                synchronized (Main.object){
                    Main.object.notify();
                }
            }
        });

        ButtonGroup group = new ButtonGroup();
        group.add(openMusic);
        group.add(closeMusic);

        openMusic.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                isPlay = true;
            }
        });
        closeMusic.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                isPlay = false;
            }
        });
    }
    public JPanel getMain() {
        return main;
    }

    @Override
    public void print(Graphics g) {
        super.print(g);
        Image img = new ImageIcon("src/images/map.jpg").getImage();
        g.drawImage(img,0,0,getSize().width,getSize().height,this);
    }
}
